package com.jinyu.jyly.view.tv;


import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;

import java.util.List;


public class DisplayUtils {



    public static <T> boolean notEmpty(List<T> list) {

        return !isEmpty(list);

    }



    public static <T> boolean isEmpty(List<T> list) {

        if (list == null || list.size() == 0) {

            return true;

        }

        return false;

    }



    // 将px值转换为dip或dp值

    public static int px2dip(Context context, float pxValue) {

        final float scale = context.getResources().getDisplayMetrics().density;

        return (int) (pxValue / scale + 0.5f);

    }



    // 将dip或dp值转换为px值

    public static int dip2px(Context context, float dipValue) {

        final float scale = context.getResources().getDisplayMetrics().density;

        return (int) (dipValue * scale + 0.5f);

    }



    // 将px值转换为sp值

    public static int px2sp(Context context, float pxValue) {

        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;

        return (int) (pxValue / fontScale + 0.5f);

    }



    // 将sp值转换为px值

    public static int sp2px(Context context, float spValue) {

        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;

        return (int) (spValue * fontScale + 0.5f);

    }



    // 屏幕宽度（像素）

    public static int getWindowWidth(Activity context) {

        DisplayMetrics metric = new DisplayMetrics();

        context.getWindowManager().getDefaultDisplay().getMetrics(metric);

        return metric.widthPixels;

    }



    // 屏幕高度（像素）

    public static int getWindowHeight(Activity context) {

        DisplayMetrics metric = new DisplayMetrics();

        context.getWindowManager().getDefaultDisplay().getMetrics(metric);

        return metric.heightPixels;

    }



    // 根据Unicode编码判断中文汉字和符号

    private static boolean isChinese(char c) {

        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);

        if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS

                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B

                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS

                || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION) {

            return true;

        }

        return false;

    }



    // 判断中文汉字和符号

    public static boolean isChinese(String strName) {

        char[] ch = strName.toCharArray();

        for (int i = 0; i < ch.length; i++) {

            char c = ch[i];

            if (isChinese(c)) {

                return true;

            }

        }

        return false;

    }



}